home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 233 / Computer Shopper 233 / ComputerShopperDVD233.iso / Toolkit / Enhance / Treesize / TreeSizePro-Demo.exe / {app} / tsizepro.xsl < prev   
Encoding:
Extensible Markup Language  |  2006-12-29  |  12.3 KB  |  335 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <xsl:output method="html" version="4.0" encoding="UTF-8" indent="yes" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" doctype-system="http://www.w3.org/TR/html4/loose.dtd" />
  4.  
  5. <!-- These declaration define the behavior of the size units. If you want to have a kB conversion for example, replace "$MB" with "$kB"
  6. However, the unit identifier is printed statically. Be sure to change them, too. -->
  7. <!-- <xsl:decimal-format decimal-separator="," grouping-separator="." /> --> <!-- setting decimal number format e.g.: 1.000,00 -->
  8. <xsl:variable name="kB">1024</xsl:variable> <!-- kB divisor -->
  9. <xsl:variable name="MB">1048576</xsl:variable> <!-- MB divisor -->
  10. <xsl:variable name="GB">1073741824</xsl:variable> <!-- GB divisor -->
  11. <xsl:variable name="Drivefs">#,##0.0#</xsl:variable> <!-- GB format string -->
  12. <xsl:variable name="Folderfs">#,##0.00</xsl:variable> <!-- MB format string -->
  13.  
  14. <xsl:template match="/Root">
  15.     <html>
  16.     <head>
  17.     <title>TreeSize Professional Report, <xsl:value-of select="Date" /></title>
  18.     <style type="text/css"> <!-- these are all the stylesheet definitions used in the output -->
  19.     body {font-family: Arial;} /* font of the other tags */
  20.     h1,h2,h3 {text-align: center;} /* center headlines */
  21.     table {font-family: Arial Narrow, Arial; padding:2px; width:100%;} /* tree-table design */
  22.     /* 
  23.         Note: If you experience UTF-8 problems, i.e. characters, which are not displayed correctly, you may want to use 
  24.         Arial instead of Arial Narrow, here. While testing, we had the problem that some arabic letters were not
  25.         available in Arial Narrow. If you are working with a system, which does not make frequent use of non Latin Characters
  26.         you should still use Arial Narrow, if possible. 
  27.     */
  28.     th {border-bottom-color: #000; border-bottom-style: solid; border-bottom-width: 1px;} /* line drawn on the bottom of the th's */
  29.     .box {display: none;} /* invisible div's */
  30.     .boxon {display: block;} /* visible div's */
  31.     .tree {font-family: Courier;} /* indention and '+'/'-' font */
  32.     .error {background-color: #FFFF88;} /* background to visualize scanning errors */
  33.     .tabbig {width: 30%; text-align: left; white-space: nowrap; cursor: pointer;} /* name column */
  34.     .tab {width: 10%; text-align: center; white-space: nowrap;} /* size column */
  35.     .tabright {width: 10%; text-align: right; white-space: nowrap;} /* compression column */
  36.     </style>
  37.     <script type="text/javascript">
  38.     <!-- JavaScript functions to create tree effects view design -->
  39.     function SwitchDisplay(node) // function which changes the visibility of the div's
  40.     {
  41.         var nextnode = node.nextSibling;  // get next sibling node
  42.         if (nextnode.style.display != "block") // change visibility into the opposite
  43.         {
  44.             nextnode.style.display = "block";
  45.         }
  46.         else
  47.         {
  48.             nextnode.style.display = "none";
  49.         }
  50.         SwitchTreeSymbol(node);
  51.     }
  52.  
  53.     function SwitchTreeSymbol(node) // function which switches the + into - and vice versa
  54.     {
  55.         var targetnode = node.firstChild.firstChild.firstChild.firstChild.firstChild.firstChild; // get suitable node (the span-tag)
  56.         if ( targetnode != null) // check if node is available
  57.         {
  58.             s = new String(targetnode.nodeValue); // get the node's text
  59.             if ((i = s.indexOf("+")) != -1) // switch tree symbol into it's opposite
  60.             {
  61.             targetnode.nodeValue = (s.substr(0,i) + "-" + s.substr(i+1,s.length));
  62.             }
  63.             else if ((i = s.indexOf("-")) != -1)
  64.             {
  65.             targetnode.nodeValue = (s.substr(0,i) + "+" + s.substr(i+1,s.length));
  66.             }
  67.         }
  68.     }
  69.  
  70.     function twodigits(n) // function which creates an extended date, e.g. "1" becomes "01"
  71.     {
  72.         if (n < 10) // if (n less than 10)
  73.             return "0" + n;
  74.         else
  75.             return n;
  76.     }
  77.  
  78.     function TimeConversion(highfiletime) // converts the FileTime value into JavaScript's intern time and then into a
  79.     {
  80.     // human-readable format. However, this is not 100% accurate, because
  81.     // only the upper 32 bits of the Windows timestamp are converted.
  82.         if (highfiletime != 0)
  83.         {
  84.             highfiletime = (highfiletime - 27111902) * 429.4967296;
  85.             var javatime = new Date(highfiletime * 1000); // JavaScript's intern time: milliseconds since 01.01.1970 00:00:00
  86.             return twodigits(javatime.getDate()) + "." + twodigits((javatime.getMonth() + 1)) + "." + javatime.getFullYear();
  87.         }
  88.         else
  89.             return "";
  90.         }
  91.     </script>
  92.     </head>
  93.     <body>
  94.     <xsl:apply-templates select="Date" />
  95.     <xsl:apply-templates select="Path" />
  96.     <xsl:if test="(ArchiveBitFilesOnly != 0) or (CreatedPastDaysOnly != 0) or (Filter/pattern != '*')">
  97.         <h3><xsl:text>Includes:</xsl:text>
  98.             <xsl:apply-templates select="ArchiveBitFilesOnly" />
  99.             <xsl:apply-templates select="CreatedPastDaysOnly" />
  100.             <xsl:apply-templates select="Filter" />
  101.         </h3>
  102.     </xsl:if>
  103.     <xsl:apply-templates select="ExcludePatterns" />
  104.     <h3>
  105.     <xsl:text>Drive:</xsl:text>
  106.     <xsl:text>  </xsl:text><xsl:apply-templates select="UsedBytesOnDrive" />
  107.     <xsl:text>  </xsl:text><xsl:apply-templates select="FreeBytesOnDrive" />
  108.     <xsl:text>  </xsl:text><xsl:apply-templates select="BytesPerCluster" /><xsl:text> Bytes</xsl:text>
  109.     <xsl:text>  Filesystem: (</xsl:text><xsl:apply-templates select="Filesystem" /><xsl:text>)</xsl:text>
  110.     </h3>
  111.     <h3>
  112.         <xsl:text>This Folder:</xsl:text>
  113.         <xsl:apply-templates select="Folder/SizeData" />
  114.     </h3>
  115.     <br />
  116.     <table cellspacing="0"> <!-- table setup -->
  117.         <tr>
  118.         <th class="tabbig">Name:</th>
  119.         <th class="tabright">Size:</th>
  120.         <th class="tabright">Allocated:</th>
  121.         <th class="tabright">Wasted:</th>
  122.         <th class="tabright">Files:</th>
  123.         <th class="tabright">Folders:</th>
  124.         <th class="tabright">Last Change:</th>
  125.         <th class="tab">Compression:</th>
  126.         </tr>
  127.     </table>
  128.     <xsl:apply-templates select="./Folder/Folder" />
  129.     </body>
  130.     </html>
  131. </xsl:template>
  132.  
  133. <xsl:template match="Date">
  134.     <h1 align="center">
  135.         <xsl:text>TreeSize Professional Report, </xsl:text>
  136.         <xsl:value-of select="." />
  137.     </h1>
  138. </xsl:template>
  139.  
  140. <xsl:template match="Path">
  141.     <h2 align="center">
  142.         <xsl:value-of select="." />
  143.     </h2>
  144. </xsl:template>
  145.  
  146. <xsl:template match="ArchiveBitFilesOnly">
  147.     <xsl:if test=". != 0">
  148.         <xsl:text>Only Files created in the past.</xsl:text>
  149.     </xsl:if>
  150. </xsl:template>
  151.  
  152. <xsl:template match="CreatedPastDaysOnly">
  153.     <xsl:if test=". != 0">
  154.         <xsl:text>Only Files with Archive Bit set.</xsl:text>
  155.     </xsl:if>
  156. </xsl:template>
  157.  
  158. <xsl:template match="Filter">
  159.     <xsl:if test="pattern != '*' ">
  160.         <xsl:value-of select="pattern" />
  161.     </xsl:if>
  162. </xsl:template>
  163.  
  164. <xsl:template match="ExcludePatterns">
  165.     <xsl:if test="pattern">
  166.         <xsl:text>Excludes: </xsl:text>
  167.         <xsl:for-each select="pattern">
  168.             <xsl:value-of select="." />
  169.             <xsl:if test="position() != last()">, </xsl:if>
  170.         </xsl:for-each>
  171.     </xsl:if>
  172. </xsl:template>
  173.  
  174. <xsl:template match="UsedBytesOnDrive"> <!-- drive size -->
  175.     <xsl:text>Size: </xsl:text>
  176.     <xsl:value-of select="format-number(. div $GB,$Drivefs)" />
  177.     <xsl:text> GB</xsl:text>
  178. </xsl:template>
  179.  
  180. <xsl:template match="FreeBytesOnDrive"> <!-- free size on drive -->
  181.     <xsl:text>Free: </xsl:text>
  182.     <xsl:value-of select="format-number(. div $GB,$Drivefs)" />
  183.     <xsl:text> GB</xsl:text>
  184. </xsl:template>
  185.  
  186. <xsl:template match="BytesPerCluster"> <!-- bytes per cluster -->
  187.     <xsl:text>Bytes per Cluster: </xsl:text>
  188.     <xsl:value-of select="." />
  189. </xsl:template>
  190.  
  191. <xsl:template match="Filesystem"> <!-- used filesystem -->
  192.     <xsl:value-of select="." />
  193. </xsl:template>
  194.  
  195. <xsl:template match="/Root/Folder/SizeData">
  196.     <xsl:text>  Size: </xsl:text>
  197.         <xsl:value-of select="format-number(@Size div $MB,$Folderfs)" /> <!-- formatting numbers -->
  198.     <xsl:text> MB</xsl:text>
  199.     <xsl:text>  Allocated: </xsl:text>
  200.         <xsl:value-of select="format-number(@Allocated div $MB,$Folderfs)" />
  201.     <xsl:text> MB</xsl:text>
  202.     <xsl:text>  Wasted: </xsl:text>
  203.         <xsl:value-of select="format-number(@Wasted div $MB,$Folderfs)" />
  204.     <xsl:text> MB</xsl:text>
  205.     <xsl:text>  Files: </xsl:text>
  206.         <xsl:value-of select="@Files" />
  207.     <xsl:text>  Folders: </xsl:text>
  208.         <xsl:value-of select="@Folders" />
  209.     <xsl:text>  Compression: </xsl:text>
  210.     <xsl:choose> <!-- Compression Test -->
  211.         <xsl:when test="@Compression = 1">
  212.             <xsl:text>no</xsl:text>
  213.         </xsl:when>
  214.         <xsl:when test="@Compression = 2">
  215.             <xsl:text>yes</xsl:text>
  216.         </xsl:when>
  217.         <xsl:when test="@Compression = 3">
  218.             <xsl:text>partial</xsl:text>
  219.         </xsl:when>
  220.         <xsl:otherwise>
  221.             <xsl:text>unknown</xsl:text>
  222.         </xsl:otherwise>
  223.     </xsl:choose>
  224. </xsl:template>
  225.  
  226. <xsl:template match="Folder">
  227.     <div onClick="SwitchDisplay(this);"> <!-- ALT <xsl:attribute name="onClick">SwitchDisplay(this);</xsl:attribute> -->
  228.             <table cellspacing="0">
  229.                 <tr>
  230.                     <td class="tabbig" title="{Name}">
  231.                         <xsl:variable name="anc_count" select="count(ancestor::Folder)-1" />
  232.                         <span class="tree">
  233.                         <xsl:call-template name="IndentRecursiveLoop"> <!-- indention and tree symbol -->
  234.                                 <xsl:with-param name="counter" select="$anc_count" />
  235.                         </xsl:call-template>
  236.                         </span>
  237.                         <xsl:if test="Error"> <!-- visualize scanning errors -->
  238.                             <span class="error" title="An Error occurred during the scan process!">
  239.                                 <xsl:text> ! </xsl:text>
  240.                             </span>
  241.                         </xsl:if>
  242.                         <xsl:call-template name="strlengthcheck">  <!-- truncates long names -->
  243.                             <xsl:with-param name="indention" select="$anc_count" />
  244.                         </xsl:call-template>
  245.                     </td>
  246.                     <xsl:apply-templates select="SizeData">
  247.                         <xsl:with-param name="LastChange" select="LastChangeDate/@High" />
  248.                     </xsl:apply-templates>
  249.                 </tr>
  250.             </table>
  251.     </div>
  252.     <div class="box"> <!-- make new nodes invisible, because of the tree structure -->
  253.     <xsl:for-each select="Folder">
  254.             <xsl:apply-templates select="." /> <!-- recursion -->
  255.     </xsl:for-each>    
  256.     </div>
  257. </xsl:template>
  258.  
  259. <xsl:template name="strlengthcheck"> <!-- truncates long names and adds "..." -->
  260.     <xsl:param name="indention" />
  261.     <xsl:choose>
  262.         <xsl:when test="(string-length(Name) + $indention) >= 28">
  263.             <xsl:value-of select="substring(Name,1,(25-$indention))" />
  264.             <xsl:text>...</xsl:text>
  265.         </xsl:when>
  266.         <xsl:otherwise>
  267.             <xsl:value-of select="Name" />
  268.         </xsl:otherwise>
  269.     </xsl:choose>
  270. </xsl:template>
  271.  
  272. <xsl:template name="IndentRecursiveLoop"> <!-- makes indention used to make the tree hierarchy visible -->
  273.     <xsl:param name="counter" />
  274.     <xsl:choose>
  275.         <xsl:when test="$counter > 0">
  276.             <xsl:text>  </xsl:text>
  277.             <xsl:call-template name="IndentRecursiveLoop">
  278.                 <xsl:with-param name="counter" select="($counter)-1" />
  279.             </xsl:call-template>
  280.         </xsl:when>
  281.         <xsl:when test="count(./Folder)">
  282.             <xsl:text>+ </xsl:text>
  283.         </xsl:when>
  284.         <xsl:otherwise>
  285.             <xsl:text>  </xsl:text>
  286.         </xsl:otherwise>
  287.     </xsl:choose>
  288. </xsl:template>
  289.  
  290. <xsl:template match="SizeData">
  291.     <xsl:param name="LastChange" />
  292.     <td class="tabright">
  293.         <xsl:value-of select="format-number(@Size div $MB,$Folderfs)" />
  294.         <xsl:text> MB</xsl:text>
  295.     </td>
  296.     <td class="tabright">
  297.         <xsl:value-of select="format-number(@Allocated div $MB,$Folderfs)" />
  298.         <xsl:text> MB</xsl:text>
  299.     </td>
  300.     <td class="tabright">
  301.         <xsl:value-of select="format-number(@Wasted div $MB,$Folderfs)" />
  302.         <xsl:text> MB</xsl:text>
  303.     </td>
  304.     <td class="tabright">
  305.         <xsl:value-of select="@Files" />
  306.     </td>
  307.     <td class="tabright">
  308.         <xsl:value-of select="@Folders" />
  309.     </td>
  310.     <xsl:variable name="uid" select="generate-id(@Size)" /> <!-- generating unique id -->
  311.     <td class="tabright" id="{$uid}"> 
  312.     <xsl:text> </xsl:text>
  313.     </td>
  314.     <script type="text/javascript">
  315.     document.getElementById("<xsl:value-of select="$uid" />").firstChild.nodeValue = TimeConversion(<xsl:value-of select="$LastChange" />);
  316.   </script>
  317.     <td class="tab">
  318.         <xsl:choose> <!-- Compression Test -->
  319.             <xsl:when test="@Compression = 1">
  320.                 <xsl:text>no</xsl:text>
  321.             </xsl:when>
  322.             <xsl:when test="@Compression = 2">
  323.                 <xsl:text>yes</xsl:text>
  324.             </xsl:when>
  325.             <xsl:when test="@Compression = 3">
  326.                 <xsl:text>partial</xsl:text>
  327.             </xsl:when>
  328.             <xsl:otherwise>
  329.                 <xsl:text>unknown</xsl:text>
  330.             </xsl:otherwise>
  331.         </xsl:choose>
  332.     </td>
  333. </xsl:template>
  334.  
  335. </xsl:stylesheet>